package com.hellobike.haxing.modules.address.util;

import com.hellobike.haxing.modules.address.entity.TCity;
import com.hellobike.haxing.modules.address.entity.TKV;
import com.hellobike.haxing.modules.address.entity.TProvince;
import com.hellobike.haxing.modules.product.entity.Category;
import com.hellobike.haxing.modules.supplier.entity.TSupplierClPro;
import com.hellobike.haxing.modules.supplier.entity.TSupplierClassification;
import com.hellobike.haxing.modules.wms.entity.Warehouse;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by zhanglei on 2020/2/5.
 */
public class Convert2KV {

    public static List<TKV> city2kv(List<TCity> cities){
        List<TKV> tkvs = new ArrayList<>();
        try {
            if(cities == null){
                return null;
            }
            for(TCity tCity : cities){
                TKV temp = new TKV();
                if(tCity != null && tCity.getId() != null){
                    temp.setK(tCity.getId().toString());
                    temp.setV(tCity.getName());
                    tkvs.add(temp);
                }
            }
        }catch (Exception e){
            e.printStackTrace();
        }
        return tkvs;
    }


    public static List<TKV> provine2kv(List<TProvince> provinces){
        List<TKV> tkvs = new ArrayList<>();
        try {
            if(provinces == null){
                return null;
            }
            for(TProvince province : provinces){
                TKV temp = new TKV();
                if(province != null && province.getId() != null) {
                    temp.setK(province.getId().toString());
                    temp.setV(province.getName());
                    tkvs.add(temp);
                }
            }
        }catch (Exception e){
            e.printStackTrace();
        }
        return tkvs;
    }

    public static List<TKV> Category2kv(List<Category> categories){
        List<TKV> tkvs = new ArrayList<>();
        try {
            if(categories == null){
                return null;
            }
            for(Category category : categories){
                TKV temp = new TKV();
                if(category != null && category.getId() != null){
                    temp.setK(category.getId().toString());
                    temp.setV(category.getName());
                    tkvs.add(temp);
                }
            }
        }catch (Exception e){
            e.printStackTrace();
        }
        return tkvs;
    }

    public static List<TKV> SupplierInfo2kv(List<TSupplierClPro> tSupplierClPros){
        List<TKV> tkvs = new ArrayList<>();
        try {
            if(tSupplierClPros == null){
                return null;
            }
            for(TSupplierClPro tSupplierInfo : tSupplierClPros){
                TKV temp = new TKV();
                if(tSupplierInfo != null && tSupplierInfo.getSupplierId() != null){
                    temp.setK(tSupplierInfo.getSupplierId().toString());
                    temp.setV(tSupplierInfo.getSupplierName());
                    tkvs.add(temp);
                }
            }
        }catch (Exception e){
            e.printStackTrace();
        }
        return tkvs;
    }

    public static List<TKV> WareHouse2kv(List<Warehouse> warehouses){
        List<TKV> tkvs = new ArrayList<>();
        try {
            if(warehouses == null){
                return null;
            }
            for(Warehouse warehouse : warehouses){
                TKV temp = new TKV();
                if(warehouse != null && warehouse.getId() != null){
                    temp.setK(warehouse.getId().toString());
                    temp.setV(warehouse.getWarehouseName());
                    tkvs.add(temp);
                }
            }
        }catch (Exception e){
            e.printStackTrace();
        }
        return tkvs;
    }

    public static List<TKV> SupplierClassT2kv(List<TSupplierClassification> tSupplierClassifications){
        List<TKV> tkvs = new ArrayList<>();
        try {
            if(tSupplierClassifications == null){
                return null;
            }
            for(TSupplierClassification tSupplierClassification : tSupplierClassifications){
                TKV temp = new TKV();
                if(tSupplierClassification != null && tSupplierClassification.getId() != null){
                    temp.setK(tSupplierClassification.getSupplierId().toString());
                    temp.setV(tSupplierClassification.getSupplierName());
                    tkvs.add(temp);
                }
            }
        }catch (Exception e){
            e.printStackTrace();
        }
        return tkvs;
    }
}
